package tugas.akhir.jason;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.ToggleButton;


public class dr2_penghuni extends Activity implements View.OnClickListener, OnCheckedChangeListener, AdapterView.OnItemSelectedListener{
	
	private String labelAlamat;
	String[] items={"1 Orang", "2 Orang", "3 Orang", "4 Orang", "5 Orang", "6 Orang", ">10 orang", "> 100 orang"};
	Spinner spin;
	Button next_button3;
	ArrayAdapter<String> aa;
	
	private ToggleButton ftogglepenghuni;
    private RadioButton fpemilik_radio, fpenyewa_radio;
    private EditText fnamapenghuni, fnokontakpenghuni;
    private Button fPOC, fNextButton;
    private String labelId;//,labelAlamat;
    private boolean fAdaPenghuni, fAdaPemilik, fAdaPenyewa;
    
    private String dr2toogle, dr2buttonpemilik, dr2buttonpenyewa;
    
    private static final String TAG = "**dr2_penghuni";
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.dr2_penghuni);
                
        TextView rid = (TextView) findViewById (R.id.dr2_label_laporan);
        labelId = "ID Laporan: " + variabelstatis.idglobal;
        rid.setText (labelId);
        

        //alamat
        TextView address = (TextView) findViewById (R.id.dr2_label_alamat);
        labelAlamat = "Alamat: " + variabelstatis.alamatglobal;
        address.setText (labelAlamat);
        
        ftogglepenghuni = (ToggleButton) findViewById (R.id.dr2_togglepenghuni);
        fpemilik_radio = (RadioButton) findViewById (R.id.dr2_radiopemilik);
        fpenyewa_radio = (RadioButton) findViewById (R.id.dr2_radiopenyewa);
        
        ftogglepenghuni.setOnCheckedChangeListener (this);
        fpemilik_radio.setOnClickListener (this);
        fpenyewa_radio.setOnClickListener (this);
        
        fpemilik_radio.setEnabled (false);
        fpenyewa_radio.setEnabled (false);
        
     // Get the renter name field.
        fnamapenghuni = (EditText) findViewById (R.id.dr2_namapenghuni);
        fnamapenghuni.setEnabled (false);

        fnokontakpenghuni = (EditText) findViewById (R.id.dr2_nokontakpenghuni);
        fnokontakpenghuni.setEnabled (false);	
        
        
        Spinner spinner = (Spinner) findViewById(R.id.dr2_jumlahpenghunispinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.array1, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new dr2_penghuni());
        	
        
        fNextButton = (Button) findViewById (R.id.next_button3);
        fNextButton.setOnClickListener (this);
        
    }
    public void onClick (View view) {
        Log.d (TAG+".onClick", "entering onClick for view " + ((Button)view).getText());
        if (view == fPOC) {
            Log.d (TAG+".onClick", "doing POC button");
        }
        
        else if (view == fNextButton) {
            variabelstatis.dr2_toogle = dr2toogle;
			variabelstatis.dr2_buttonpemilik = dr2buttonpemilik;
			variabelstatis.dr2_buttonpenyewa = dr2buttonpenyewa;
			variabelstatis.dr2_namapenghuni = (fnamapenghuni.getText().toString());
			variabelstatis.dr2_nomorkontak = (fnokontakpenghuni.getText().toString());
            
            Intent dr2 = new Intent (this, dr3_asuransi.class);
            startActivity (dr2);
        } 
        
        else if (view == fpemilik_radio) {
            Log.d (TAG+".onClick", "handling click on owner home radio button");
            fAdaPemilik = true;
            fAdaPenyewa = false;
            fnamapenghuni.setText ("");
            fnamapenghuni.setHint ("nama pemilik");
            fnamapenghuni.setEnabled (true);
            fnokontakpenghuni.setText ("");
            fnokontakpenghuni.setHint ("nomor kontak");
            fnokontakpenghuni.setEnabled (true);
            dr2buttonpemilik = "1";
            dr2buttonpenyewa = "0";
        }
        
        else if (view == fpenyewa_radio) {
            fAdaPemilik = false;
            fAdaPenyewa = true;
            fnamapenghuni.setHint ("nama penyewa");
            fnamapenghuni.setEnabled (true);          
            fnokontakpenghuni.setHint ("nomor kontak");
            fnokontakpenghuni.setEnabled (true);
            dr2buttonpemilik = "0";
            dr2buttonpenyewa = "1";
        }
    } // onClick
    
    @Override
    public void onActivityResult (int request_code, int result_code, Intent result) {
        Log.d (TAG + ".onActivityResult", "enter with request_code " + request_code + " and result_code " + result_code);
    } // onActivityResult
    
    public void onCheckedChanged (CompoundButton toggle, boolean state) {
        if (toggle == ftogglepenghuni) {
            fAdaPenghuni = state;
            fpemilik_radio.setEnabled (state);
            fpenyewa_radio.setEnabled (state);
            dr2toogle = "1";
            if (!state) {
                fnamapenghuni.setHint ("");
                fnamapenghuni.setEnabled (false);
                fnokontakpenghuni.setHint ("");
                fnokontakpenghuni.setEnabled (false);
                fpemilik_radio.setChecked (false);
                fpenyewa_radio.setChecked (false);
                dr2toogle = "0";
            } 
        }
    }
    
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		variabelstatis.dr2_jumlahpenghuni = arg0.getItemAtPosition(arg2).toString();

	}
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub	
	}
}    